package com.cfx.exercise_32;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class TestIO1 {
   //复制一个图片
	public static void main(String[] args) throws IOException {
		File file = new File("C:/Users/zs/Desktop/测试IO.jpg");
		BufferedInputStream bis = null;
		BufferedOutputStream bos = null;
		try {
				bis = new BufferedInputStream(new FileInputStream(file));
				bos = new BufferedOutputStream(new FileOutputStream("C:/Users/zs/Desktop/复制图片.jpg"));
				byte[] ch = new byte[1024*169];//当1024时读169次，当是1024*169时读一次，当是1024*168时读两次。。。。
				int len = 0;
				int i = 0;
				while( (len = bis.read(ch))!= -1){
					bos.write(ch,0,len);
					bos.flush();
					i++;
				}
				System.out.println("复制成功");
				System.out.println(i);
		} catch (FileNotFoundException e) {			
			e.printStackTrace();
		}finally{
			bos.close();
			bis.close();
		}
	}
}
